import random

#userbase = {'12345678': {'username': "杨宇博", 'passwd': "123456", 'balance': "500", 'bank_name': "中国工商银行昌平支行", 'country': "中国",'province': "河南省", 'street': "北山口", 'Number': "01"}}


class Bank:
    trycount = "" #输入次数
    bank_id = ""  #账户
    username = "" #用户名
    passwd = "" #密码
    country = "" #国家
    province = "" #省份
    street = "" #街道
    Number = "" #门牌号
    address = "" # 地址
    balance = 0 #余额
    deposit = "" #存款
    account = "" #开户
    bank_name = "中国工商银行昌平分支" #银行名
    userbase = {12345678:{'username':"杨宇博",'passwd':123456,'balance':500.00,'bank_name':"中国工商银行昌平支行",'country':"中国",'province':"河南省",'street':"北山口",'Number':"01"}}

#开户
    def account(self):
        print(self.userbase)
        self.bank_id = random.randint(1000000, 99999999)
        self.username = input("请输入您的姓名：")
        self.province = input("请输入省份：")
        self.country = input("请输入国家：")
        self.street = input("请输入街道：")
        self.Number = input("请输入门牌号：")

        while True: #判断密码格式
            self.passwd = input("请输入您的6位密码：")
            if len(self.passwd) != 6:
                print("输入的密码格式错误，请重新输入！！！！")
            elif self.passwd.isdigit() == False:
                print("输入密码格式错误，请重新输入！！！！")
            else:
                self.passwd = int(self.passwd)
                print("输入密码成功")
                print("请记住您的账号：",self.bank_id)
                break

#生成的开户信息

        # self.userbase1 = {'12345678': {'username': "杨宇博", 'passwd': "123456", 'balance': "500", 'bank_name': "中国工商银行昌平支",'country': "中国", 'province': "河南省", 'street': "北山口", 'Number': "01"}}
        # print(self.bank_id,self.userbase1[bank_id])
        self.userbase[self.bank_id] = {'username': self.username, 'passwd': self.passwd,'balance': self.balance,'country':self.country,'province':self.province,'street':self.street,'Number':self.Number,'bank_name':self.bank_name,'bank_id':self.bank_id}
        print(self.bank_id,self.userbase[self.bank_id])
        if len(self.userbase) == 100:
            print("用户仓库已满，请联系管理员")
            return 0
        elif len(self.userbase) < 100:
            if self.bank_id in self.userbase.keys():
                print("开户成功")
                return 1
        else:
            print("账号重复")
            return 2


#输入密码次数

    def save(self):
        trycount = 0
        while trycount <= 3:
            a = int(input("请输入您的银行卡号："))
            b = int(input("请输入您的密码："))
            if a in self.userbase and b == self.userbase[a]['passwd']:  #如果a并且b满足
                print("登录成功")
                money = input("请输入存款金额：")
                self.userbase[a]['balance'] += money
                print("你当前余额为：",self.userbase[a]['balance'])
                print(self.userbase[a])
                break
            # elif a in self.userbase1 and b == self.userbase1[a]['passwd']:
            #     print("登录成功")
            #     money = input("请输入存款金额：")
            #     self.userbase1[a]['balance'] += money
            #     print("你当前余额为：", self.userbase1[a]['balance'])
            #     print(self.userbase1[a])
            #     break
            else:
                print("账号或密码错误，请重新输入！！")
                trycount += 1

#取钱
    def getMoney(self):
        while True:
            a = int(input("请输入您的银行卡号："))
            if a in self.userbase:
                b = int(input("请输入您的密码："))
                if b == self.userbase[a]['passwd']:
                    money = float(input("请输入您的取出的金额："))
                    if self.userbase[a]['balance'] >= money:
                        self.userbase[a]['balance'] -= money
                        print("取款成功，当前余额为：", self.userbase[a]['balance'])
                        break
                    else:
                        print("余额不足！当前余额为：", self.userbase[a]['balance'])
                        return

                else:
                    print("输入密码错误，请重新输入！！！")
                    return


            else:
                print("账号不存在，请重新输入！！！！！")




#查询
    def enquiry(self):
        while True:
            a =int(input("请输入账号："))
            if a in self.userbase:
                print("账号正确")
                b = int(input("请输入密码："))
                if b == self.userbase[a]['passwd']:
                    print("查询成功")
                    print(self.userbase[a])
                    break
                else:
                    print("密码错误，请重新输入")
            else:
                print("用户名不存在")

#转账
    def giveMoney(self):
        while True:
            a = int(input("请输入您的银行卡号："))
            if a in self.userbase:
                b = int(input("请输入您的密码："))
                if b == self.userbase[a]['passwd']:
                    c = int(input("请输入收款账号："))
                    if a in self.userbase and c in self.userbase and c!=a:
                        givemoney = float(input("请输入转账金额："))
                        if self.userbase[a]['balance'] >= givemoney:
                            self.userbase[a]['balance'] -= givemoney
                            self.userbase[c]['balance'] += givemoney
                            print("转账成功，您的余额为：", self.userbase[a]['balance'])
                            print("收款成功，您的余额为：", self.userbase[c]['balance'])
                            break
                        else:
                            print("余额不足，当前余额为：", self.userbase[a]['balance'])
                            return 3
                    else:
                        print("相同账号不能进行转账，请重新输入！！！")
                        return 2

                else:
                    print("密码错误，请重新输入！")
                    return 1
            else:
                print("转账账号不存在，请重新输入！！")
                return 0

#主程序

while True:
    print("**********************************************")
    print("*          欢迎登录中国工商银行系统              *")
    print('*                 账户管理系统                 *')
    print('*                    v1.0                    *')
    print("**********************************************")
    print("**********************************************")
    print("*           （1）开户                         *")
    print("*           （2）存钱                         *")
    print("*           （3）取钱                         *")
    print("*           （4）转账                         *")
    print("*           （5）查询                         *")
    print("*           （6）bye                         *")
    print("**********************************************")

    a = input('请输入您的要求：')
    a = int(a)

    if a == 1:
        d = Bank().account()
        if d == 1:
            print("成功")
        elif d ==2:
            print("重复")
    elif a == 2:
        if Bank().save() is True:
            print("self.balance")
    elif a == 3:
        if Bank().getMoney() is True:
            print()
    elif a == 4:
        d = Bank().giveMoney()
        print()
    elif a == 5:
        if Bank().enquiry() is True:
            print()
    elif a == 6:
        print("祝您生活愉快，欢迎下次再来！")
        break




